package com.dxhackday.ppicker;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;

/**
 * @author Sergey Lyadzhin
 * @since 24.11.12 15:47
 */
public class  ApplicationConfig {
    public static final String FILE_CONFIG = "ppicker.properties";

    private Properties properties = new Properties();

    public void load() throws IOException {
        try (FileInputStream in = new FileInputStream(FILE_CONFIG)) {
            properties.load(in);
        } catch (FileNotFoundException e) {
            // ignore
        }
    }

    public void save() throws IOException {
        try (FileOutputStream out = new FileOutputStream(FILE_CONFIG)) {
            String comments = new Date().toString();
            properties.store(out, comments);
        } catch (FileNotFoundException e) {
            // ignore
        }
    }

    public boolean isSkipCountdown() {
        return Boolean.valueOf(properties.getProperty("skip.countdown"));
    }

    public void setInputDir(String inputDir) {
        properties.setProperty("input.dir", inputDir);
    }

    public String getInputDir() {
        return properties.getProperty("input.dir");
    }

    public String getGoodDir() {
        return properties.getProperty("good.dir");
    }

    public int getDelay() {
        try {
            return Integer.parseInt(properties.getProperty("delay"));
        } catch (NumberFormatException e) {
            return 1000;
        }
    }


}
